package androidx.fragment.app;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import o.FragmentManager;
import o.FragmentTransaction;

@Deprecated
public class FragmentTabHost extends TabHost implements OnTabChangeListener {
    private boolean ʽ;
    private final ArrayList<c> ˊ = new ArrayList();
    private FragmentManager ˋ;
    private int ˎ;
    private FrameLayout ˏ;
    private Context ॱ;
    private c ॱॱ;
    private OnTabChangeListener ᐝ;

    static class SavedState extends BaseSavedState {
        public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return ˋ(parcel);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return ˊ(i);
            }

            public SavedState ˋ(Parcel parcel) {
                return new SavedState(parcel);
            }

            public SavedState[] ˊ(int i) {
                return new SavedState[i];
            }
        };
        String ˎ;

        SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        SavedState(Parcel parcel) {
            super(parcel);
            this.ˎ = parcel.readString();
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeString(this.ˎ);
        }

        public String toString() {
            return "FragmentTabHost.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " curTab=" + this.ˎ + "}";
        }
    }

    static final class c {
        @Nullable
        final Bundle ˊ;
        @NonNull
        final Class<?> ˋ;
        Fragment ˎ;
        @NonNull
        final String ॱ;
    }

    @Deprecated
    public FragmentTabHost(@NonNull Context context) {
        super(context, null);
        ˋ(context, null);
    }

    @Deprecated
    public FragmentTabHost(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        ˋ(context, attributeSet);
    }

    private void ˋ(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842995}, 0, 0);
        this.ˎ = obtainStyledAttributes.getResourceId(0, 0);
        obtainStyledAttributes.recycle();
        super.setOnTabChangedListener(this);
    }

    private void ˊ(Context context) {
        if (findViewById(16908307) == null) {
            View linearLayout = new LinearLayout(context);
            linearLayout.setOrientation(1);
            addView(linearLayout, new LayoutParams(-1, -1));
            View tabWidget = new TabWidget(context);
            tabWidget.setId(16908307);
            tabWidget.setOrientation(0);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, -2, 0.0f));
            tabWidget = new FrameLayout(context);
            tabWidget.setId(16908305);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(0, 0, 0.0f));
            tabWidget = new FrameLayout(context);
            this.ˏ = tabWidget;
            this.ˏ.setId(this.ˎ);
            linearLayout.addView(tabWidget, new LinearLayout.LayoutParams(-1, 0, 1.0f));
        }
    }

    @Deprecated
    public void setup() {
        throw new IllegalStateException("Must call setup() that takes a Context and FragmentManager");
    }

    @Deprecated
    public void setup(@NonNull Context context, @NonNull FragmentManager juVar) {
        ˊ(context);
        super.setup();
        this.ॱ = context;
        this.ˋ = juVar;
        ˋ();
    }

    @Deprecated
    public void setup(@NonNull Context context, @NonNull FragmentManager juVar, int i) {
        ˊ(context);
        super.setup();
        this.ॱ = context;
        this.ˋ = juVar;
        this.ˎ = i;
        ˋ();
        this.ˏ.setId(i);
        if (getId() == -1) {
            setId(16908306);
        }
    }

    private void ˋ() {
        if (this.ˏ == null) {
            this.ˏ = (FrameLayout) findViewById(this.ˎ);
            if (this.ˏ == null) {
                throw new IllegalStateException("No tab content FrameLayout found for id " + this.ˎ);
            }
        }
    }

    @Deprecated
    public void setOnTabChangedListener(@Nullable OnTabChangeListener onTabChangeListener) {
        this.ᐝ = onTabChangeListener;
    }

    @Deprecated
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        String currentTabTag = getCurrentTabTag();
        FragmentTransaction kaVar = null;
        int size = this.ˊ.size();
        for (int i = 0; i < size; i++) {
            c cVar = (c) this.ˊ.get(i);
            cVar.ˎ = this.ˋ.findFragmentByTag(cVar.ॱ);
            if (!(cVar.ˎ == null || cVar.ˎ.ʼॱ())) {
                if (cVar.ॱ.equals(currentTabTag)) {
                    this.ॱॱ = cVar;
                } else {
                    if (kaVar == null) {
                        kaVar = this.ˋ.ˊ();
                    }
                    kaVar.ˋ(cVar.ˎ);
                }
            }
        }
        this.ʽ = true;
        FragmentTransaction ॱ = ॱ(currentTabTag, kaVar);
        if (ॱ != null) {
            ॱ.ˏ();
            this.ˋ.ॱ();
        }
    }

    @Deprecated
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.ʽ = false;
    }

    @NonNull
    @Deprecated
    protected Parcelable onSaveInstanceState() {
        Parcelable savedState = new SavedState(super.onSaveInstanceState());
        savedState.ˎ = getCurrentTabTag();
        return savedState;
    }

    @Deprecated
    protected void onRestoreInstanceState(@SuppressLint({"UnknownNullness"}) Parcelable parcelable) {
        if (parcelable instanceof SavedState) {
            SavedState savedState = (SavedState) parcelable;
            super.onRestoreInstanceState(savedState.getSuperState());
            setCurrentTabByTag(savedState.ˎ);
            return;
        }
        super.onRestoreInstanceState(parcelable);
    }

    @Deprecated
    public void onTabChanged(@Nullable String str) {
        if (this.ʽ) {
            FragmentTransaction ॱ = ॱ(str, null);
            if (ॱ != null) {
                ॱ.ˏ();
            }
        }
        if (this.ᐝ != null) {
            this.ᐝ.onTabChanged(str);
        }
    }

    @Nullable
    private FragmentTransaction ॱ(@Nullable String str, @Nullable FragmentTransaction kaVar) {
        c ˏ = ˏ(str);
        if (this.ॱॱ != ˏ) {
            if (kaVar == null) {
                kaVar = this.ˋ.ˊ();
            }
            if (!(this.ॱॱ == null || this.ॱॱ.ˎ == null)) {
                kaVar.ˋ(this.ॱॱ.ˎ);
            }
            if (ˏ != null) {
                if (ˏ.ˎ == null) {
                    ˏ.ˎ = this.ˋ.ˋ().ॱ(this.ॱ.getClassLoader(), ˏ.ˋ.getName());
                    ˏ.ˎ.ʼ(ˏ.ˊ);
                    kaVar.ॱ(this.ˎ, ˏ.ˎ, ˏ.ॱ);
                } else {
                    kaVar.ˎ(ˏ.ˎ);
                }
            }
            this.ॱॱ = ˏ;
        }
        return kaVar;
    }

    @Nullable
    private c ˏ(String str) {
        int size = this.ˊ.size();
        for (int i = 0; i < size; i++) {
            c cVar = (c) this.ˊ.get(i);
            if (cVar.ॱ.equals(str)) {
                return cVar;
            }
        }
        return null;
    }
}
